package com.docmgmt.mvp.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.docmgmt.mvp.entity.AiDialogEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * AI对话Mapper
 */
@Mapper
public interface AiDialogMapper extends BaseMapper<AiDialogEntity> {

    /**
     * 查询用户的所有对话（按最后查询时间倒序，只返回活跃对话）
     */
    @Select("SELECT * FROM ai_dialog WHERE user_id = #{userId} AND status = 'active' ORDER BY last_query_time DESC")
    List<AiDialogEntity> selectDialogsByUserId(@Param("userId") Long userId);

    /**
     * 更新对话轮数和最后查询时间
     */
    @Select("UPDATE ai_dialog SET total_rounds = total_rounds + 1, last_query_time = NOW() WHERE id = #{dialogId}")
    void incrementConversationCount(@Param("dialogId") Long dialogId);
}
